<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>

    </style>
</head>
<body>
<div id="app">


    <div class="a">
        <template>
                    <div id="box1">
                        <div class="yq-tab-content-item active" >
                            <div class="yq-btn-list" id="hy" v-for="(s,i) in hosdinfo">
                                <dl></dl>
                                <dt><span>{{s.bname}}</span></dt>
                                <dd></dd><br/><el-divider></el-divider>
                                <el-button id="haha" type="button" class="yq-btn" v-for="(g,t) in s.hosd"@click="hosdDepart(g.id)"  >
                                    <span>{{g.kname}}</span>
                                </el-button>
                                <br/><br/><br/><br/>
                            </div>
                        </div>
                    </div>
                    <div id="box2">
                        <template>
                            <el-table :data="doctorArr" border style="width: 100%">
                                <el-table-column  prop="kname"label="科室" width="160"> </el-table-column>
                                <el-table-column prop="name" label="医生姓名" width="160"></el-table-column>
                                <el-table-column prop="telephone" label="医生电话号码" width="160"> </el-table-column>
                                <el-table-column prop="number" label="可预约人数" width="160"></el-table-column>
                                <el-table-column prop="price" label="预约费用" width="160"> </el-table-column>
                                <el-table-column prop="time" label="预约日期" width="160"> </el-table-column>

                                <el-table-column label="操作">
                                    <template  slot-scope="scope">
                                        <el-button  v-if="scope.row.number>=1" type="danger" @click="register(scope.row.yid)">预约</el-button>
                                        <el-button  v-if="scope.row.number==0" type="danger" disabled>预约</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                        <el-button type="info"@click="btn()">上一步</el-button>
                    </div>

                    <div id="box3">
                        <el-form :model="staff" status-icon :rules="rules" ref="staff" label-width="100px" class="demo-ruleForm">
                            <el-form-item label="姓名" prop="name">
                                <el-input   v-model="staff.name" ></el-input>
                            </el-form-item>
                            <el-form-item label="身份证号" prop="identity">
                                <el-input  v-model="staff.identity" ></el-input>
                            </el-form-item>
                            <el-form-item label="年龄" prop="age">
                                <el-input  v-model="staff.age" ></el-input>
                            </el-form-item>
                            <el-form-item label="手机号" prop="telephone">
                                <el-input  v-model="staff.telephone" ></el-input>
                            </el-form-item>
                            <el-form-item label="性别" prop="gender">
                                <el-radio-group v-model="staff.gender">
                                    <el-radio label="男"></el-radio>
                                    <el-radio label="女"></el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item>
                                <el-button type="primary"@click="submitForm('staff')" >立即预约</el-button>
                                <!--<el-button @click="resetForm('staff')">重置</el-button>-->

                            </el-form-item>
                        </el-form>
                        </fieldset>

                        <el-button type="info"@click="btn2()">上一步</el-button>
                    </div>
        </template>
    </div>
</div>

<script>

    $.get("/ssm/Udepart/list",function(backData){
        haha.hosdinfo=backData.data;
    });
    // $.get("/ssm/user/getInfo",function (backData) {
    //     haha.userInfo=backData.data;
    // });
    var haha = new Vue({
        el:"#app",
        data:{
            activeName: 'first',
            hosdinfo:[],
            // userInfo:{},
            doctorArr:[],
            staff:{},
            doctor:{
                price:""
            },
            rules: {
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' },

                ],
                age: [
                    { required: true, message: '请输入年龄', trigger: 'blur' },

                ],
                identity: [
                    { required: true, message: '请输入身份证号', trigger: 'blur' },
                    {min: 18,max: 18,message: '长度在 18个字符',trigger: 'blur'}
                ],
                telephone: [
                    { required: true, message: '请输入手机号', trigger: 'blur' },
                    {min: 11,max: 11,message: '长度在 11个字符',trigger: 'blur'}
                ],
                gender: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
            },
        },
        methods:{

            hosdDepart(id){
                $("#box1").hide();

                $("#box2").show();

                $("#box3").hide();
                $.post("/ssm/Udepart/departId/"+id ,function (backData) {
                    haha.doctorArr=backData.data;
                })
            },
            btn(){
                $("#box1").show();

                $("#box2").hide();

                $("#box3").hide();
            },
            register(yid){
                $("#box1").hide();

                $("#box2").hide();

                $("#box3").show();
                $.post("/ssm/Udepart/doctor/"+yid,function (backData) {
                    haha.doctor = backData.data;
                });
            },

            submitForm() {
                haha.$refs["staff"].validate((valid) => {
                    if (valid) {



                        $.post("/ssm/Udepart/subscribe",haha.staff ,function (backData) {
                            if(backData.code==2){
                                haha.$message.error(backData.msg);}
                            else if(backData.code==1){

                                $.post("/ssm/Udepart/lost",function (backData) {
                                    if (backData.code==1){
                                        haha.$message.success("挂号成功");



                                        var outTradeNo = Math.random()*10000000;
                                        var subject = 'd';
                                        var totalAmount = 10;

                                        location.href="/ssm/zhifu.html?outTradeNo="+outTradeNo+"&subject="+subject+"&totalAmount="+totalAmount;
                                 }



                                });

                            }

                        });
                    }
                });
            },
            btn2(){
                $("#box1").hide();

                $("#box2").show();

                $("#box3").hide();
            }
        },

    });

    $("#box2").hide();
    $("#box3").hide();

</script>
</body>
</html>
